$(function(){
 $('#grid').datagrid({
    title : '您所在的位置：行业资讯管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;行业资讯管理',
    width:1000,
    height:400,
    nowrap: false,
	striped: true,
	collapsible:false,
    url:'statement_queryStatementManage.shtml',
    frozenColumns:[[
	                {field:'ck',title:'选择',checkbox:true}
	                ]],
    columns:[[
			        {title:'基本信息',colspan:2},
					{field:'opt',title:'操作',width:150,align:'center', rowspan:2,
						formatter:function(value,rec){
						return '<span style="color:red"><span onclick=Onmodify("'+rec.id+'")>修改</span> <span onclick=Ondelete("'+rec.id+'")>删除</span>&nbsp;<a href="javascript:changeWeights(\''+rec.weight+'\',\''+rec.id+'\')">修改权重</a></span>';
						}
					}
				],[ 
					{field:'title',title:'标题',width:350},
				    {field : 'weight',	title : '权重',	align : 'center',width : 200,formatter:function(value){if(value==null) return "0";else return value}}
				]],
				pagination:true,
				rownumbers:true,
				queryParams:{
				},
				toolbar:[{
					id:'btnadd',
					text:'添加声明',
					iconCls:'icon-add',
					handler:function(){
						$(this).attr("href",'statement_toStatementInfo.shtml');
						
					}
				 },'-',{
					id : 'btnclose',
					text : '  &nbsp;关  闭',
					iconCls : 'icon-cancel',
					handler : function() {
						window.self.close();
					}
				}]
				}
				
		
         
);
    	 var page = $("#grid").datagrid("getPager").pagination("options");
			page.beforePageText = '第';
		   page.afterPageText = '页,共{pages}页';
			page.displayMsg = '显示从 {from} 至 {to} / {total} 的数据';
			
	$("#modifyWindow").dialog({
		title:'修改权重',
		width:300,
		height:120,
		resizable:false,
		minimizable:false,
		maximizable:false,
		toolbar: [{
			text : '保存信息',
		    iconCls:'icon-save',
		    handler:function(){
						var url1 = "statement_modifyWeights.shtml";
						var weights = $("#weightValue").val();
						var infoId = $("#infoId").val();
						if(isNaN(weights)){
							alert("权重值只能为数字");
							return;
						}
						$.ajax({
							url : url1,
							data : "id=" + infoId+"&weights="+weights,
							success : function(msg) {
								if(msg=="1"){
									alert("保存成功");							
								}else{
									alert("保存失败");
								}
									$("#modifyWindow").dialog('close');
								$('#grid').datagrid("reload");
								
							}
						});
		    }
		  }],
		closed:true
	})		
			
});


function changeWeights(weights,infoId) {
	$("#weightValue").val(weights);
	$("#infoId").val(infoId);
	$("#modifyWindow").window('open');
}

   

    function   Ondelete(id){ 
          if(id =="undefined") {alert("此条记录已删除");
             return;
          }
          if(confirm("确定删除此条信息吗?")){
                 var url1 ="statement_delete.shtml";
             $.ajax({
                   url: url1,
                   data: "id="+id,
                 success: function(msg){
                     var obj=eval('('+msg+')');
                     var result=obj[0]["message"];
                     alert(result);
                     window.location.reload();
                 }
                });
          }
     }
     
      function Onmodify(id){
       window.location.href="statement_toStatementInfo.shtml?id="+id;
     }
     
     
